namespace Vanilla.UI

import Vanilla

class FileThumbnail (ImageGadget):
	public File as File
	public ThumbnailSize as Size
	public Callback as callable

	def constructor (p as Box, f as File, s as Size, c as callable):
		thumb as BitmapCanvas = null
		try:
			tool = f.Type.ToolForAction("GenerateThumbnail") as IGenerateThumbnail
			thumb = tool.GenerateThumbnail(f, s)
		except e:
			print "-WARNING- unhandled exception while generating thumbnail for ${f.Path}:"
			print e
			thumb = BitmapCanvas(s.Width, s.Height)
		
		super(p, thumb)
		
		CloneOnDrag = true
		File = f
		ThumbnailSize = s
		Callback = c
		CanDrag = true
	
	def constructor (p as Box, f as File):
		self(p, f, Size(System.Math.Min(p.Size.Width-(p.Spacing*2), p.Size.Height-(p.Spacing*2)),
		                System.Math.Min(p.Size.Width-(p.Spacing*2), p.Size.Height-(p.Spacing*2))),
		           f.Open)
	
	override def Click (b as MouseButton, x as double, y as double):
		Callback()
	
	override def Clone ():
		return FileThumbnail(null, File, ThumbnailSize, Callback)
	

class Icon (Column):
	public File as File
	Callback as callable(Icon)
	
	public Thumbnail as Gadget
	public Label as Label
	
	override MaxSize as Size:
		get:
			return MinSize

	def constructor (p as Box, f as File, c as callable(Icon)):
		super(p)
		CloneOnDrag = true
		File = f
		Callback = c
		DrawFrame = false
		Spacing = 3
		PassMouseEventsToChildren = false
		CanDrag = true
		
		Thumbnail = FileThumbnail(self, f, Size(90,90), {print "unreachable"})
		Label = Label(self, f.Name)
	
	//def constructor (p as Box, f as File):
	//	self(p, f, {i as Icon | i.DefaultAction()})
		
	override def Click (b as MouseButton, x as double, y as double):
		if b == MouseButton.Left:
			File.Open()
		else:
			print "right clickity"
	
	override def Clone ():
		return Icon(null, File, Callback)
		
